/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/* 
 * File:   Mesh.cpp
 * Author: ever
 * 
 * Created on 2018年1月24日, 下午8:53
 */

#include "Mesh.h"

Mesh::Mesh() : _num(0), _len(0), _point_pos(0), _data(NULL) {

}

Mesh::Mesh(const Mesh& orig) {
}

Mesh::~Mesh() {
}

void Mesh::setData(const char * data, int len) {
    _data = (const unsigned char *)data;
    _len = len;
    if (_len < 32) {
        //
        _data = NULL;
        _len = 0;
        return;
    }
    //_num = 0;
    //unsigned char * udata = _data;
    _point_pos = 0;
    _num = (_data[17] << 8) + _data[18];
}

int Mesh::getNum() {
    return _num;
}

void Mesh::getTimeStr(string& str) {
    char tmp[64];
    //str.
    int n = snprintf(tmp, 64, "%4d-%02d-%02d %02d:%02d:%02d",
            _data[11] + 2000, _data[12], _data[13], _data[14], _data[15], _data[16]);
    str.assign(tmp, n);
}

bool Mesh::hasNext() {
    return _point_pos < _num;
}

time_t Mesh::getTime(){
    string tmstr;
    getTimeStr(tmstr);
    return TL_Datetime::parse(tmstr,"%Y-%m-%d %H:%M:%S");
}
